package org.example.bookstore.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.example.bookstore.custom.ResultVO;
import org.example.bookstore.pojo.DO.Address;
import org.example.bookstore.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "地址Api")
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    //  地址添加
    @Operation(summary = "地址添加")
    @PostMapping("/add")
    public ResultVO<?> addAddress(@RequestBody Address address){
        return addressService.insertAddress(address);
    }

    //  地址删除
    @Operation(summary = "地址删除")
    @GetMapping("/del")
    public ResultVO<?> delAddress(@Parameter(name = "id", description = "地  址id") @RequestParam Integer id){
        return addressService.delAddress(id);
    }

    //  地址修改
    @Operation(summary = "地址修改")
    @PostMapping("/update")
    public ResultVO<?> UpdateAddress(@RequestBody Address address){
        return addressService.UpdateAddress(address);
    }

    //  查询用户所有地址
    @Operation(summary = "查询用户所有地址")
    @GetMapping("/getAddressAll")
    public ResultVO<?> getAddressAll(@Parameter(name = "id", description = "用户id") @RequestParam Integer id){
        return addressService.getAddress(id);
    }

}
